package com.xy.core.shiro;


import com.xy.core.init.InitMybatisTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

public class MyInitalizing implements
        ApplicationListener<ContextRefreshedEvent> {
    protected final Logger log = LoggerFactory.getLogger(MyInitalizing.class);
    @Autowired
    private MethodToStaticCache methodToStaticCache;
    @Autowired
    private InitMybatisTable initMybatisTable;

        private static boolean  b = false;

       public void onApplicationEvent(ContextRefreshedEvent event) {
           if(!b){
               b=true;
               log.info("程序运行自动加载。。。。。");
               //加入缓存
               try {
                   methodToStaticCache.addCache();
                   log.info("加入菜单缓存成功。。。。。");
               } catch (Exception e) {
                   e.printStackTrace();
                   log.error("加入菜单缓存失败。。。。。",e);
               }

               //自动补全表属性
               try {
                   initMybatisTable.run();
                   log.info("自动补全表属性成功。。。。。");
               } catch (Exception e) {
                   e.printStackTrace();
                   log.error("自动补全表属性失败。。。。。");
               }


           }

        }
}
